package com.hkts.management.orderrecord.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.orderrecord.entity.HktsOrderRecord;
import com.hkts.management.orderrecord.service.IHktsOrderRecordService;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.utils.CustomPageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author hml
 * @since 2021-04-22
 */
@RestController
@RequestMapping("/order/hktsOrderRecord")
@Api(tags = "订单记录管理接口")
public class HktsOrderRecordController {
    private final Logger logger = LoggerFactory.getLogger(HktsOrderRecordController.class);

    @Autowired
    public IHktsOrderRecordService iHktsOrderRecordService;

    /**
     * 分页查询数据
     *
     * @param page            分页信息
     * @param hktsOrderRecord 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsOrderRecordPageList")
    public Result<Object> getHontUserList(Page<HktsOrderRecord> page, HktsOrderRecord hktsOrderRecord) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsOrderRecordService.selectPage(page, hktsOrderRecord)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsOrderRecord 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsOrderRecordSave")
    public Result<Object> hktsOrderRecordSave(HktsOrderRecord hktsOrderRecord) {
        iHktsOrderRecordService.saveOrUpdate(hktsOrderRecord);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsOrderRecordGetById")
    public Result<Object> hktsOrderRecordGetById(String id) {
        HktsOrderRecord byId = iHktsOrderRecordService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsOrderRecordDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsOrderRecordService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsOrderRecordBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsOrderRecordService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 根据订单id获取订单记录
     */
    @ResponseBody
    @GetMapping("/getOrderRecord")
    @ApiOperation(value = "根据订单id获取订单记录")
    public Result<Object> getOrderRecord( HktsOrderRecord hktsOrderRecord){
        List<HktsOrderRecord> orderRecords=iHktsOrderRecordService.selectList(hktsOrderRecord);
        return ResultUtil.data(orderRecords);
    }
    /**
     * 添加订单记录
     */
    @ResponseBody
    @GetMapping("/addOrderRecord")
    @ApiOperation(value = "添加订单记录")
    public Result<Object> addOrderRecord(String orderId,String driverName,int orderSubStatus){
        iHktsOrderRecordService.addOrderRecord( orderId, driverName,orderSubStatus);
        return ResultUtil.success("添加成功");
    }

}
